﻿@model IViewModel
@{
    if (Model.Messages.IsEmpty())
    {
        return; // no Message
    }

    var severities = new Dictionary<string, Severity>
    {
        {"Error", Severity.Error},
        {"Warning", Severity.Warning},
        {"Information", Severity.Info},
    };

    var content = new PlaceHolder(); //Div("divMessages");
    foreach (var pair in severities)
    {
        if (Model.Messages.Any(msg => msg.Severity.Equals(pair.Value)))
        {
            // a message table
            var table = new DefinitionList(PercentForLabel.p00);

            foreach (Message msg in Model.Messages.Where(msg => msg.Severity == pair.Value))
            {
                table.AddControls
                (
                    new DD
                    {
                        new Div()
                        .SetTitle(GetLocalized("TemplateUsed") + (": \"" + msg.Template ?? string.Empty + "\" "))
                        .AddControls
                        (
                            new Literal(msg.Text.ToLength(400))
                        ),
                        ViewContext.HttpContext.IsCustomErrorEnabled // debug details
                        || !msg.DebugDetails.IsNotEmpty()
                         ? null
                         : new Pre { new Literal (msg.DebugDetails) },
                        new Small("right") { new Literal(GetLocalized(msg.Reporter).ToLength(150)) },
                    }
                );
            }

            // Fieldset for the message table
            content.AddControls
            (
                new Fieldset("message w98p fieldset" + pair.Key, pair.Key)
                {
                    table,
                }
            );
        }
    }
}
@AddControls(content)